using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace MuseumsBC.Activities
{
    [Activity(Label = "Museums")]
    public class ListMuseumsActivity : Activity
    {
        private ListView _list;
        
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Create your application here
            SetContentView(Resource.Layout.ListMuseums);

            _list = FindViewById<ListView>(Resource.ListMuseums.MuseumsList);
            _list.ItemClick += new System.EventHandler<ItemEventArgs>(_list_ItemClick);
        }

        protected override void OnResume()
        {
            base.OnResume();

            RefreshMuseums();
        }

        private void RefreshMuseums()
        {
            var museums = ((MuseumsBCApplication)Application).MuseumRepository.GetAllMuseums();
            _list.Adapter = new MuseumsListAdapter(this, museums);
            _list.ChoiceMode = 1;
        }

        private void _list_ItemClick(object sender, ItemEventArgs e)
        {
            var museum = ((MuseumsListAdapter)_list.Adapter).GetNote(e.Position);

            var intent = new Intent();
            intent.SetClass(this, typeof(MuseumDetailActivity));
            intent.PutExtra("MuseumId", museum.Id.ToString());
            //intent.PutExtra("MuseumListAdapterPosition", e.Position);


            StartActivity(intent);

            //var intent = new Intent();
            //intent.SetClass(this, typeof(SecondActivity));
            //intent.PutExtra("Title", museum.MuseumName);
            //intent.PutExtra("Contents", museum.ChinCode);

            //StartActivity(intent);
        }
    }
}